import NetDispatcher = require("../utility/netdispather");
import ActorEventDispatcher = require("../actor/actorevent");

class TestSystem {

    private system_id: number = 0;
    public  system_type: number = 0;
    public static readonly system_name: string = "TestSystem";
    //_G: any["name"] = "test"; // 测试全局变量
    private static _instance: TestSystem;
    
    public constructor() 
    {
        //注册网络消息
        NetDispatcher.reg(this.OnNetReqTestDataMsg, Protocol.CMD_Base, Protocol_Base.cBaseCmd_GmCmd);
        ActorEventDispatcher.regEvent(ActorEventId.OnLogin,this.OnActorLoginEvent);
    }
    
    public static getInstance() {
        if (!TestSystem._instance) {
            TestSystem._instance = new TestSystem();
        }
        return TestSystem._instance;
    }

    private OnActorLoginEvent(actor: any):void {
        // 处理登录逻辑...
        console.log("OnActorLogin");
    }

    private OnNetReqTestDataMsg(actor: any, net_pack: any):void {
        // 处理网络消息的逻辑...
        console.log("OnNetReqTestDataMsg");
    }
    // 修改所有方法为静态方法
    private  getActorstaticData(actor: any): actorBaseData | null {
        let varData = LActor.getStaticData(actor);
        if (!varData) return null;
        // 使用更简洁的对象初始化
        varData.baseData ??= {
            actorId: 0,
            name: LActor.getName(actor),
            tdata: { 
                type: 10,
                value: 10,
                array_info: [1, 2, 3]
            }
        };
        const baseData = varData.baseData as actorBaseData;
        baseData.name ??= LActor.getName(actor);
        return baseData;
    }
    // 导出方法改为静态
    public  getTestData(actor: any): testData | null {
        const svar = this.getActorstaticData(actor);
        return svar?.tdata ?? null;
    }
    // 事件处理函数改为静态
    public  OnInit() {
        // 初始化逻辑...
    }
    
    public  TestPrintFuncPublic() {
        console.log("TestPrintFuncPublic");
    }

    private  TestPrintFuncPrivate() {
        this.TestPrintFuncPublic();
        console.log("TestPrintFuncPrivate");
    }
}
export = new TestSystem;